﻿var arrColor = new Array();
var arrAllBigImages = new Array();
var colorParentControl = "ulColor";
var sizeParentControl = "ulSize";
var colorDisplayControl = "spanColor";
var sizeDisplayControl = "spanSize";
var sizeSectionControl = "sizeSectionControl";
var ulSize = "ulSize";
var colorCodeControl = "hidColorCode";
var colorDescControl = "hidColorDesc";
var sizeCodeControl = "hidSizeCode";
var sizeDescControl = "hidSizeDesc";
var bigImagesControl = "divBigPic";
var smallImagesControl = "ulSmallPic";
var recommendedPriceControl = "ctl00_cpContent_ChooseProduct1_div_MarketPrice";
var redwebPrice = "p_PanicPrice";
var basePriceControl = "ctl00_cpContent_ChooseProduct1_div_MarketPrice";
var webPriceControl = "ctl00_cpContent_ChooseProduct1_div_ProductPrice";
var webPrice = "p_WebPrice";
var ltrMarketPrice = "ltrMarketPrice"
var ltrbasePrice = "ltrbasePrice";
var redwebPriceControl = "ctl00_cpContent_ChooseProduct1_div_panicbuying";
var staffPriceControl = "ctl00_cpContent_ChooseProduct1_div_emplyee";
var basePointControl = "ltlPoint";
var litPointSingle = "ltlPointSingle";
var ibtnChangeCodeForSale = "ibtnChangeCodeForSale";
var firstLoadFlag = true;
var ibtnQH = "lbl_QH";
var hfProductType = "ctl00_cpContent_ChooseProduct1_hfProductType";
var hdshop_item_code = "ctl00_cpContent_ChooseProduct1_hdshop_item_code";
var hdshop_id = "ctl00_cpContent_ChooseProduct1_hdshop_id";
var lbl_OVS = "ctl00_cpContent_ChooseProduct1_lbl_OVS";
var spProduct = "ctl00_cpContent_ChooseProduct1_spProduct";
var lbl_noproduct = "ctl00_cpContent_ChooseProduct1_lbl_noproduct";
var itemTypeIconExpression = ".pimgs .pimgs_icolayer a"

Array.prototype.contain = function (o) {
    var result = false;
    for (var obj in this) {
        if (o == obj) {
            result = true;
            break;
        }
    }
    return result;
}
Array.prototype.outersect = function (arr) {
    var arrOutersect = new Array();
    for (var i = 0; i < this.length; i++) {
        var intersectFlag = false;
        for (var j = 0; j < arr.length; j++) {
            if (this[i] == arr[j]) {
                intersectFlag = true;
                break;
            }
        }
        if (!intersectFlag) {
            arrOutersect.push(this[i]);
        }
    }
    return arrOutersect;
}
var GenerateColor = function () {
    if (arrColor.length > 0) {

        $(arrColor).each(function () {
            CreateSingleColor(this);
        });
        if (defaultSknColor == "") {
            ColorChange(arrColor[0].Code);
        }
        else {
            ColorChange(defaultSknColor);
        }
    }
}
var CreateSingleColor = function (colorItem) {
    var colorItemHTML = "<a href=\"JavaScript:ColorChange('" + colorItem.Code + "')\"  title=\"" + colorItem.Desc + colorItem.SknDesc + "\" id=\"color" + colorItem.Code + "\" >";
    colorItemHTML += "<sub></sub>";
    if (ColorImgCount > 0) {
        colorItemHTML += "<img src=\"../product/prodimg/color/" + colorItem.SKN + "_" + colorItem.Code + ".jpg\" />";
    }
    else {
        //colorItemHTML += "<img src=\"../product/prodimg/color/000000_00.jpg\" />";
        colorItemHTML += colorItem.Desc;
    }
    colorItemHTML += "</a>";
    $("#" + colorParentControl).append(colorItemHTML)
}
var ColorChange = function (colorCode) {
    ColorReset();
    $("#color" + colorCode).append("<sub></sub>");
    $("#color" + colorCode).addClass("xz");

    var colorItem = GetColorItemByCode(colorCode);
    if (colorItem != null && typeof (colorItem) != "undefined") {
        $("#" + colorCodeControl).val(colorItem.Code);
        $("#" + colorDescControl).val(colorItem.Desc);
        $("#" + colorDisplayControl).empty();
        $("#" + colorDisplayControl).append(colorItem.Desc);

        GenerateSize(colorItem);
        GenerateImages(colorItem);

        var sizeList = colorItem.SizeList;
        //商品付款方式随颜色改变 2013-10-30
        SetPaymentType(colorItem.SKN, colorItem.Code, sizeList[0].Code);
        $('.infiniteCarousel').infiniteCarousel();
    }
}
var ColorReset = function () {
    $(arrColor).each(function () {
        $("#color" + this.Code + " sub").remove();
        $("#color" + this.Code).removeClass("xz");
    });
}
var GetColorItemByCode = function (colorCode) {
    var colorItem;
    $(arrColor).each(function () {
        if (this.Code == colorCode) {
            colorItem = this;
            return false;
        }
    });
    return colorItem;
}
var GenerateSize = function (colorItem) {
    $("#" + sizeParentControl).empty();

    var sizeList = colorItem.SizeList;

    if (sizeList.length == 1 && sizeList[0].Desc.length == 0) {
        $("#" + sizeSectionControl).hide();
        $("#" + ulSize).hide();
    }
    else {
        $("#" + sizeSectionControl).show();
        $(sizeList).each(function (i) {
            CreateSingleSize(colorItem.Code, this, colorItem.Desc, sizeList[i].Desc);
        });
    }
    SizeChange(colorItem.Code, sizeList[0].Code, colorItem.Desc, sizeList[0].Desc);
}
var CreateSingleSize = function (colorCode, sizeItem, colorDesc, sizeDesc) {
    var sizeItemHTML = "<a id=\"size" + sizeItem.Code + "\"  href=\"Javascript:SizeChange('" + colorCode + "', '" + sizeItem.Code + "','" + colorDesc + "', '" + sizeDesc + "')\" >";
    sizeItemHTML += "<sub></sub>";
    sizeItemHTML += sizeItem.Desc;
    sizeItemHTML += "</a>";
    $("#" + sizeParentControl).append(sizeItemHTML)
}
var SizeChange = function (colorCode, sizeCode, colorDesc, sizeDesc) {
    var color = "";
    var size = "";
    if (colorDesc != "") {
        color = colorDesc + "";
    }

    if (sizeDesc != "") {
        if (color != "") {
            size = "/" + sizeDesc + "码";
        } else {
            size = "" + sizeDesc + "码";
        }
    }
    if (colorDesc == "" && sizeDesc == "") {
        $("#itemcolorsize").html("");
    } else {
        $("#itemcolorsize").html(" 已选择 " + color + size + "");
    }
    var colorItem = GetColorItemByCode(colorCode);
    //商品付款方式随尺寸改变 2013-10-30
    if (colorItem != null && typeof (colorItem) != "undefined") {
        SetPaymentType(colorItem.SKN, colorCode, sizeCode);
    }
    SizeReset(colorCode);
    $("#size" + sizeCode).addClass("xz").append("<sub></sub>");
    var sizeItem = GetSizeItemByCode(colorCode, sizeCode);
    if (sizeItem != null && typeof (sizeItem) != "undefined") {
        $("#" + sizeCodeControl).val(sizeItem.Code);
        $("#" + sizeDescControl).val(sizeItem.Desc);
        $("#" + sizeDisplayControl).empty();
        $("#" + sizeDisplayControl).append(sizeItem.Desc);
        var price;
        var basePriceFlag = ExistDoc(ltrbasePrice);
        var recommendedPriceFlag = ExistDoc(recommendedPriceControl);
        var ltrMarketPriceFlag = ExistDoc(ltrMarketPrice);
        var saveMoney = GetSaveMoney(sizeItem.RecommendedPrice, sizeItem.BasePrice, sizeItem.WebPrice);
        var Spread = GetSpread(sizeItem.BasePrice, sizeItem.WebPrice);
        var redSaveMoney = GetRedSaveMoney(sizeItem.BasePrice, sizeItem.WebPrice);
        if (recommendedPriceFlag && ltrMarketPriceFlag) {
            GetDoc(recommendedPriceControl).innerHTML = "<p id='ltrMarketPrice'><font>市场价：</font><span><del id='p_MarketPrice'>" + sizeItem.RecommendedPrice + "元</del></span></p>";
        }

        if (ExistDoc(basePriceControl) && basePriceFlag) {

            if (recommendedPriceFlag && ltrMarketPriceFlag) {
                if (Spread > 0) {
                    GetDoc(basePriceControl).innerHTML = "<p id='ltrMarketPrice'><font>市场价：</font><span><del id='p_MarketPrice'>" + sizeItem.RecommendedPrice + "元</del></span></p>" + "<p id='ltrbasePrice'><font>宜佳价：</font><span><del id='p_BasePrice' >" + sizeItem.BasePrice + "元</del></span><span>&nbsp;</span><span style='color:#BC0001;font-size:15px;'>立减" + Spread + "元</span></p>";
                }
                else {
                    GetDoc(basePriceControl).innerHTML = "<p id='ltrMarketPrice'><font>市场价：</font><span><del id='p_MarketPrice'>" + sizeItem.RecommendedPrice + "元</del></span></p>" + "<p id='ltrbasePrice'><font>宜佳价：</font><span><del id='p_BasePrice' >" + sizeItem.BasePrice + "元</del></span></p>";
                }
            }
            else {
                if (Spread > 0) {
                    GetDoc(basePriceControl).innerHTML = "<p id='ltrbasePrice'><font>宜佳价：</font><span><del id='p_BasePrice' >" + sizeItem.BasePrice + "元</del></span><span>&nbsp;</span><span style='color:#BC0001;font-size:15px;'>立减" + Spread + "元</span></p>";
                }
                else {
                    GetDoc(basePriceControl).innerHTML = "<p id='ltrbasePrice'><font>宜佳价：</font><span><del id='p_BasePrice' >" + sizeItem.BasePrice + "元</del></span></p>";
                }
            }
        }
        if (ExistDoc(webPriceControl) || !ExistDoc(redwebPriceControl)) {
            if (saveMoney > 0) {
                GetDoc(webPriceControl).innerHTML = "<p><font>优惠价：</font><span id='p_WebPrice'>¥" + sizeItem.WebPrice + "</span><em>(为您节省了" + saveMoney + "元)</em></p>";
            } else {
                GetDoc(webPriceControl).innerHTML = "<p><font>优惠价：</font><span id='p_WebPrice'>¥" + sizeItem.WebPrice + "</span></p>";
            }
            price = replaceMoney(GetDoc(webPrice).innerHTML);
        }

        if (ExistDoc(redwebPriceControl)) {
            /*红色星期五*/
            GetDoc(webPriceControl).innerHTML = "<p><font>优惠价：</font><span id='p_WebPrice'>¥" + sizeItem.BasePrice + "</span></p>";
            if (redSaveMoney > 0) {
                GetDoc(redwebPriceControl).innerHTML = "<p><font>抢购价格：</font><span id='p_PanicPrice'>¥" + sizeItem.WebPrice + "</span><em>(为您节省了" + redSaveMoney + "元)</em></p>";
            }
            else {
                GetDoc(redwebPriceControl).innerHTML = "<p><font>抢购价格：</font><span id='p_PanicPrice'>¥" + sizeItem.WebPrice + "</span></p>";
            }
            price = replaceMoney(GetDoc(redwebPrice).innerHTML);

        }

        if (ExistDoc(staffPriceControl)) {
            if (sizeItem.shop_id != "") {
                GetDoc(staffPriceControl).innerHTML = "<p><font>员工价格：</font><span id='p_EmplyeePrice' >¥" + sizeItem.StaffPrice + "</span><span style='color:#d0000b;font-size:12px;padding:4px;'>宅急送上门收款，不用先到财务处付款</span></p>";
            }
            else {

                GetDoc(staffPriceControl).innerHTML = "<p><font>员工价格：</font><span id='p_EmplyeePrice' >¥" + sizeItem.StaffPrice + "</span><span style='color:#d0000b;font-size:12px;padding:4px;'>下单后请至财务付款方能发货</span></p>";

            }
        }
        if (ExistDoc(basePointControl)) {
            GetDoc(litPointSingle).innerHTML = "<em>=（" + sizeItem.Point + "元购物积分+" + sizeItem.Point + "元网购积分</em>";
            GetDoc(basePointControl).innerHTML = sizeItem.BasePoint;
        }



        if (price > 0) {
            displayaddtocartButton("")
        }
        else {
            if (GetDoc(hfProductType).value == "PWP") {
                GetDoc(addtocartButton).style.display = "";
            }
            else {
                displayaddtocartButton("none")
            }
        }

        //FitemID
        GetDoc(hdshop_item_code).value = sizeItem.shop_item_code;
        GetDoc(hdshop_id).value = sizeItem.shop_id;
        $("#sp_warehouse_desc").html(sizeItem.warehouse_desc);

        //隐藏按钮
        displayCodeForSale("none");
        displayQHButton("none");
        $(".buy_button .buy05")[0].style.display = "none";

        //停售
        if (sizeItem.web_flag == "K") {

            $(".pdesc_c .p_stock")[0].style.display = "none";
            $(".pdesc_c .buy_num")[0].style.display = "none";
            $(".buy_button .buy01")[0].style.display = "none";
            $(".buy_button .buy02")[0].style.display = "none";
            $(".buy_button .buy07")[0].style.display = "block";
            $(".buy_button .buy04")[0].style.display = "block";

            if (!ChangeCodeForSale(ibtnChangeCodeForSale, sizeItem)) {

                $(".buy_button span").each(function (i) {
                    this.style.display = "none";
                });

                GetDoc("ImabStopSell").style.display = "block";
                GetDoc("ImabStopSell").disabled = true;
            }
            return;
        } else {
            //GetDoc("UpdatePanel6").style.display = "block";
            //GetDoc("inventoryDiv").style.display = "block";
            GetDoc("ImabStopSell").style.display = "none";
            GetDoc("ImabStopSell").disabled = false;
        }

        if (sizeItem.AvailQty <= 0 && sizeItem.OvsFlag == "Y") {

            GetDoc("txtNoProduct").style.display = "none";
            GetDoc(lbl_noproduct).style.display = "block";
            displayQHButton("block");
            GetDoc(lbl_OVS).style.display = "block";
            GetDoc(spProduct).style.display = "none"; //需要补货

            if (ExistDoc(addtocartButton)) {
                GetDoc(addtocartButton).src = "../images/prds_detail_30.png";
                GetDoc(addtocartButton).disabled = false;
                GetDoc(addtocartButton).style.display = "";
            }

        }
        else if (sizeItem.AvailQty <= 0 && sizeItem.OvsFlag == "N") {//没货
            GetDoc("txtNoProduct").style.display = "block";
            GetDoc(lbl_OVS).style.display = "none";
            GetDoc(spProduct).style.display = "none";
            GetDoc(lbl_noproduct).style.display = "block";

            $(".buy_button .buy01")[0].style.display = "none";
            $(".buy_button .buy02")[0].style.display = "none";
            $(".buy_button .buy05")[0].style.display = "block";

            var rel_skn = sizeItem.rel_skn;
            if (rel_skn == "") {
                displayQHButton("block");
            }

            ChangeCodeForSale(ibtnChangeCodeForSale, sizeItem);
        }
        else {

            //现货
            if (ExistDoc(addtocartButton)) {
                GetDoc(addtocartButton).src = "../images/prds_detail_30.png";
                GetDoc(addtocartButton).disabled = false;
            }
            GetDoc(lbl_OVS).style.display = "none";
            GetDoc(spProduct).style.display = "block";
            GetDoc(lbl_noproduct).style.display = "none";
            displayQHButton("none");
            if (GetDoc(addtocartButton) != null) {
                GetDoc(addtocartButton).style.display = "";
            }
            $(".buy_button .buy01")[0].style.display = "block";
            $(".buy_button .buy02")[0].style.display = "block";
        }

        if (sizeItem.WebPrice <= 0) {
            $(".buy_button .buy06")[0].style.display = "block";
            $(".buy_button .buy01")[0].style.display = "none";
            $(".buy_button .buy02")[0].style.display = "none";
        }
    }
}
var SizeReset = function (colorCode) {
    var colorItem = GetColorItemByCode(colorCode);
    if (colorItem != null && typeof (colorItem) != "undefined") {
        var sizeList = colorItem.SizeList;
        $(sizeList).each(function () {
            $("#size" + this.Code + " sub").remove();
            $("#size" + this.Code).removeClass("xz");
        });
    }
}
var GetSizeItemByCode = function (colorCode, sizeCode) {
    var sizeItem;
    var colorItem = GetColorItemByCode(colorCode);
    if (colorItem != null && typeof (colorItem) != "undefined") {
        var sizeList = colorItem.SizeList;
        $(sizeList).each(function () {
            if (this.Code == sizeCode) {
                sizeItem = this;
                return false;
            }
        });
    }
    return sizeItem;
}

var GenerateImages = function (colorItem) {
    if (firstLoadFlag) {
        GenerateBigImages(colorItem);
    }
    GenerateSmallImages(colorItem);
    firstLoadFlag = false;
}
var GenerateBigImages = function (colorItem) {
    $("#" + bigImagesControl).empty();
    var bigImageList = colorItem.BigImageList;
    var desc = colorItem.SknDesc;

    var webitemtype = colorItem.WebItemType;
    var sizeList = colorItem.SizeList;
    if (sizeList.length > 0) {
        var sizeItem = GetSizeItemByCode(colorItem.Code, sizeList[0].Code);
    }
    if (bigImageList.length > 0) {
        for (var i = 0; i < bigImageList.length; i++) {
            if (sizeItem != null && typeof (sizeItem) != "undefined") {
                CreateSingleBigImageAndDownPrice(bigImageList[i], true, i, desc, webitemtype, sizeItem.BasePrice, sizeItem.WebPrice);
            }
            else {
                CreateSingleBigImage(bigImageList[i], true, i, desc, webitemtype);
            }
        }
        var arrOutersect = arrAllBigImages.outersect(bigImageList);
        for (var i = 0; i < arrOutersect.length; i++) {

            if (sizeItem != null && typeof (sizeItem) != "undefined") {
                CreateSingleBigImageAndDownPrice(arrOutersect[i],false, i, desc, webitemtype, sizeItem.BasePrice, sizeItem.WebPrice);
            }
            else {
                CreateSingleBigImage(arrOutersect[i], false, i, desc, webitemtype);
            }
        }
    }
    else {
        if (sizeItem != null && typeof (sizeItem) != "undefined") {
            CreateDefaultBigImageAndDownPrice(webitemtype, desc, sizeItem.BasePrice, sizeItem.WebPrice);
        }
        else {
            CreateDefaultBigImage(webitemtype, desc);
        }
    }
}
var CreateSingleBigImage = function (imageName, shouldDisplay, index, desc, webitemtype) {
    $(itemTypeIconExpression).empty();
    if (webitemtype == "SHOP") {
        var imageItemHTML = "";
        imageItemHTML += "<div>";
        imageItemHTML += "<a rel=\"clearbox[product]\" title=\"\" href=\"/product/prodimg/xxxl/" + imageName + "\">";
        imageItemHTML += "<img id=\"bigImage" + imageName + "\" src=\"/product/prodimg/xxl/" + imageName + "\"" + (shouldDisplay && index == 0 ? "" : " style=\"display:none;\"") + "  alt='" + desc + "'/>";
        imageItemHTML += "</a>";
        imageItemHTML += "</div>";
        $(itemTypeIconExpression).append("<img alt=\"品牌直送 网购独享\" src=\"/product/prodimg/images/ppzs_wgtx.gif\" complete=\"complete\"/>");
    }
    else if (webitemtype == "TV") {
        var imageItemHTML = "";
        imageItemHTML += "<div>";
        imageItemHTML += "<a rel=\"clearbox[product]\" title=\"\" href=\"/product/prodimg/xxxl/" + imageName + "\">";
        imageItemHTML += "<img id=\"bigImage" + imageName + "\" src=\"/product/prodimg/xxl/" + imageName + "\"" + (shouldDisplay && index == 0 ? "" : " style=\"display:none;\"") + "  alt='" + desc + "'/>";
        imageItemHTML += "</a>";
        imageItemHTML += "</div>";
        $(itemTypeIconExpression).append("<img alt=\"TV热销\" src=\"/product/prodimg/images/tv_rx.gif\" complete=\"complete\"/>");
    }
    else {
        var imageItemHTML = "";
        imageItemHTML += "<div>";
        imageItemHTML += "<a rel=\"clearbox[product]\" title=\"\" href=\"/product/prodimg/xxxl/" + imageName + "\">";
        imageItemHTML += "<img id=\"bigImage" + imageName + "\" src=\"/product/prodimg/xxl/" + imageName + "\"" + (shouldDisplay && index == 0 ? "" : " style=\"display:none;\"") + "  alt='" + desc + "'/>";
        imageItemHTML += "</a>";
        imageItemHTML += "</div>";
    }
    $("#" + bigImagesControl).append(imageItemHTML)
}
//产品页面添加直降图片
var CreateSingleBigImageAndDownPrice = function (imageName, shouldDisplay, index, desc, webitemtype, baseprice, webprice) {
    $(itemTypeIconExpression).empty();
    if (webitemtype == "SHOP") {
        var imageItemHTML = "";
        imageItemHTML += "<div>";
        imageItemHTML += "<a rel=\"clearbox[product]\" title=\"\" href=\"/product/prodimg/xxxl/" + imageName + "\">";
        imageItemHTML += "<img id=\"bigImage" + imageName + "\" src=\"/product/prodimg/xxl/" + imageName + "\"" + (shouldDisplay && index == 0 ? "" : " style=\"display:none;\"") + "  alt='" + desc + "'/>";
        imageItemHTML += "</a>";
        imageItemHTML += "</div>";
        $(itemTypeIconExpression).append("<img alt=\"品牌直送 网购独享\" src=\"/product/prodimg/images/ppzs_wgtx.gif\" complete=\"complete\"/>");
    }
    else if (webitemtype == "TV") {
        var imageItemHTML = "";
        imageItemHTML += "<div>";
        imageItemHTML += "<a rel=\"clearbox[product]\" title=\"\" href=\"/product/prodimg/xxxl/" + imageName + "\">";
        imageItemHTML += "<img id=\"bigImage" + imageName + "\" src=\"/product/prodimg/xxl/" + imageName + "\"" + (shouldDisplay && index == 0 ? "" : " style=\"display:none;\"") + "  alt='" + desc + "'/>";
        imageItemHTML += "</a>";
        imageItemHTML += "</div>";
        $(itemTypeIconExpression).append("<img alt=\"TV热销\" src=\"/product/prodimg/images/tv_rx.gif\" complete=\"complete\"/>");
    }
    else {
        var imageItemHTML = "";
        imageItemHTML += "<div>";
        imageItemHTML += "<a rel=\"clearbox[product]\" title=\"\" href=\"/product/prodimg/xxxl/" + imageName + "\">";
        imageItemHTML += "<img id=\"bigImage" + imageName + "\" src=\"/product/prodimg/xxl/" + imageName + "\"" + (shouldDisplay && index == 0 ? "" : " style=\"display:none;\"") + "  alt='" + desc + "'/>";
        imageItemHTML += "</a>";
        imageItemHTML += "</div>";
    }
    //若无播放视频，显示直降
    if ($("#ctl00_cpContent_ChooseProduct1_tagvideo").length == 0) {
        if (baseprice > 0 && baseprice > webprice) {
            var downPrice = GetDownPrice(baseprice, webprice);
            imageItemHTML += "<a href=\"#\" class=\"zjicon ie6filter\" id=\"downprice\"><span><em>¥</em>" + downPrice + "</span></a>";
        }
    }
    $("#" + bigImagesControl).append(imageItemHTML)
}
var CreateDefaultBigImage = function (webitemtype, desc) {
    var imageItemHTML = "";
    imageItemHTML += "<div>";
    imageItemHTML += "<img src=\"/product/prodimg/xxl/000000_00_00.jpg\" alt='" + desc + "' />";
    imageItemHTML += "</div>";
    $("#" + bigImagesControl).append(imageItemHTML)
}
//产品页面添加直降图片
var CreateDefaultBigImageAndDownPrice = function (webitemtype, desc, baseprice, webprice) {
    var imageItemHTML = "";
    imageItemHTML += "<div>";
    imageItemHTML += "<img src=\"/product/prodimg/xxl/000000_00_00.jpg\" alt='" + desc + "' />";
    imageItemHTML += "</div>";
    //若无播放视频，显示直降
    if ($("#ctl00_cpContent_ChooseProduct1_tagvideo").length == 0) {
        if (baseprice > 0 && baseprice > webprice) {
            var downPrice = GetDownPrice(baseprice, webprice);
            imageItemHTML += "<a href=\"#\" class=\"zjicon ie6filter\" id=\"downprice\"><span><em>¥</em>" + downPrice + "</span></a>";
        }
    }
    $("#" + bigImagesControl).append(imageItemHTML)
}
var GenerateSmallImages = function (colorItem) {
    $("#" + smallImagesControl).empty();
    var smallImageList = colorItem.SmallImageList;
    if (smallImageList.length > 0) {
        for (var i = 0; i < smallImageList.length; i++) {
            CreateSingleSmallImage(smallImageList[i]);
        }
        ChangeImage(smallImageList[0]);
    }
    else {
        CreateDefaultSmallImage();
    }
}
var CreateSingleSmallImage = function (imageName) {
    var imageItemHTML = "<li>";
    imageItemHTML += "<a onclick=\"ChangeImage('" + imageName + "');\">";
    imageItemHTML += "<img src=\"/product/prodimg/s/" + imageName + "\">";
    imageItemHTML += "</a></li>";
    $("#" + smallImagesControl).append(imageItemHTML)
}
var CreateDefaultSmallImage = function () {
    var imageItemHTML = "<li><img src=\"/product/prodimg/s/000000_00_00.jpg\" /></li>";
    $("#" + smallImagesControl).append(imageItemHTML)
}
var ChangeImage = function (imageName) {
    var bigImages = GetDoc(bigImagesControl).getElementsByTagName("IMG");
    for (var i = 0; i < bigImages.length; i++) {
        if (bigImages[i].name == "tv" || bigImages[i].name == "ppzx") {
            bigImages[i].style.display = '';
        }
        else if (bigImages[i].id == "bigImage" + imageName) {
            bigImages[i].style.display = '';
        }

        else {
            bigImages[i].style.display = 'none';
        }
    }
}
var GenerateAllBigImages = function () {
    $(arrColor).each(function () {
        var bigImageList = this.BigImageList;
        var skn = this.SKN;
        for (var i = 0; i < bigImageList.length; i++) {
            if (!arrAllBigImages.contain(bigImageList[i])) {
                arrAllBigImages.push(bigImageList[i]);
            }
        }
    });
}


//显示换码销售逻辑
function ChangeCodeForSale(ibtnChangeCodeForSale, sizeItem) {
    var rel_skn = sizeItem.rel_skn;

    if (rel_skn != "") {
        displayQHButton("none");
        displayaddtocartButton("none");
        displayCodeForSale("block");
        SetDocAHref(ibtnChangeCodeForSale, "../prod/p.aspx?skn=" + rel_skn);
        return true;
    }
    return false;
}

//设置A标签的连接地址
function SetDocAHref(obj, strHref) {
    if (ExistDoc(obj)) {
        GetDoc(obj).href = strHref;
    }
}
//显示隐藏换码销售
function displayCodeForSale(display) {
    if (ExistDoc(ibtnChangeCodeForSale)) {
        GetDoc(ibtnChangeCodeForSale).style.display = display;
    }
}

//显示隐藏购买按钮
function displayaddtocartButton(display) {
    if (ExistDoc(addtocartButton)) {
        GetDoc(addtocartButton).style.display = display;
    }
}
//显示隐藏到货通知按钮
function displayQHButton(display) {
    if (ExistDoc(ibtnQH)) {
        GetDoc(ibtnQH).style.display = display;
    }
}

//获取文档对象
function GetDoc(objId) {
    return document.getElementById(objId);
}

//是否存在Doc节点
function ExistDoc(objId) {
    if (GetDoc(objId) != null) {
        return true;
    } else { return false; }
}

function replaceMoney(spanMoney) {
    spanMoney = spanMoney.replace("¥", "")
    spanMoney = spanMoney.replace("元", "")
    return spanMoney;
}

function GetSaveMoney(pWebMarketPrice,pWebBasePrice,pWebWebPrice) {
    var WebMarketPrice = parseFloat(pWebMarketPrice);
    var WebBasePrice = parseFloat(pWebBasePrice);
    var WebWebPrice = parseFloat(pWebWebPrice);

    if (WebMarketPrice < WebWebPrice) {
        return 0;
    }

    if (WebBasePrice > WebMarketPrice) {
        
        return WebBasePrice - WebWebPrice;
    }
    else {
        return WebMarketPrice - WebWebPrice;
    }
}

function GetSpread(pWebBasePrice, pWebWebPrice) {
    var WebBasePrice = parseFloat(pWebBasePrice);
    var WebWebPrice = parseFloat(pWebWebPrice);

    if (WebBasePrice > WebWebPrice) {
        return WebBasePrice - WebWebPrice;
    }
    else {
        return 0;
    }
}
function GetRedSaveMoney(pWebBasePrice, pWebPanicPrice) {
        var WebBasePrice = parseFloat(pWebBasePrice);
        var WebPanicPrice = parseFloat(pWebPanicPrice);
        if (WebBasePrice > WebPanicPrice) {
            return WebBasePrice - WebPanicPrice;
        }
        else {
            return 0;
        }
    }
    function GetDownPrice(pBasePrice,pWebPrice) {
        var  WebPrice= parseFloat(pWebPrice);
        var  BasePrice= parseFloat(pBasePrice);
        if (BasePrice > WebPrice) {
            return BasePrice - WebPrice;
        }
        else {
            return 0;
        }
    }
    //根据商品SKN、颜色、尺寸设置商品付款方式
    function SetPaymentType(skn,colorcode,sizecode) {
        $.ajax({
            type: "post",
            url: "../handler/CommonHandler.ashx",
            data: "func=GetProductPaymentType&skn=" + skn + "&color=" + colorcode + "&size=" + sizecode,
            dataType: "json",
            success: function (jsonObj) {
                if (jsonObj.success) {
                    if (jsonObj.paymentType == 0) {
                        $("#PaymentType").html("货到付款、支付宝");
                    }
                    else if (jsonObj.paymentType == 1) {
                        $("#PaymentType").html("货到付款");
                    }
                    else {
                        $("#PaymentType").html("支付宝");
                    }
                }
                else {
                    alert(jsonObj.msg);
                }
            }
        });
    }
 
